package edu.sctu.zhuyingzhi.month201505.day20150522.ioTest;

import java.io.FileInputStream;
import java.io.FileOutputStream;

/**
 * Created by user13 on 2015/5/22.
 */
public class TextRead {
    public void readtext(){
        byte[] buffer = new byte[200];

        try{
            FileInputStream file = new FileInputStream("src\\main\\java\\edu\\sctu\\zhuyingzhi\\day20150522\\ioTest\\text.txt");
            int bytes = file.read(buffer,0,200);
            System.out.println(bytes);
            System.out.println((char)buffer[2]);
            String str = new String(buffer,0,bytes,"gb2312");
            System.out.println(str);

        }catch (Exception e){
            String err = e.toString();
            System.out.println(err);
        }
    }

    public void writeText(){
        byte[] content = new byte[200];
        try{
            FileOutputStream file = new FileOutputStream("src\\main\\java\\edu\\sctu\\zhuyingzhi\\day20150522\\ioTest\\text.txt");
            for (int i = 0; i < 20; i++) {
                content[i] = 8;
            }
            file.write(content);
        }catch (Exception e){
            String err = e.toString();
            System.out.println(err);
        }
    }
}
